package fr.pascal.composite;

import java.util.LinkedList;

public class Composite implements IComponent {

	private final String name;
	private LinkedList<IComponent> components;

	public Composite(String name) {
		this.name = name;
		this.components = new LinkedList<IComponent>();
	}

	public void addComponent(IComponent component) {
		components.add(component);
	}

	public void removeComponent(IComponent component) {
		components.remove(component);
	}

	public void print(int depth) {
		int _depth = depth;
		String spaces = "";
		while (_depth-- > 0) {
			spaces += " ";
		}
		System.out.println(String.format("%s<%s>", spaces, name));
		for (IComponent c : components) {
			c.print(depth + 4);
		}
		System.out.println(String.format("%s</%s>", spaces, name));
	}
}
